# 作者: 陈其志 
# 2025年02月20日16时14分20秒 
# 2716847110@qq.com

class Person:
    def __init__(self, name, age, weight):
        """
        定义类的属性
        :param name:
        :param age:
        :param weight:
        """
        self.name = name
        self.age = age
        self.weight = weight

    def __str__(self):
        """

        :return:
        """
        return f"{self.name}体重现在是{self.weight}"

    def run(self):
        """
        定义类的方法
        :return:
        """
        self.weight -= 0.5
        print(f"{self.name}跑了步，体重减少到{self.weight}")

    def eat(self):
        """
        定义类的吃方法
        :return:
        """
        self.weight += 1
        print(f"{self.name}吃了饭，体重增加到{self.weight}")


class HouseItem:
    # 先创建依赖项，再创建被依赖项
    def __init__(self, item_name, area):
        self.item_name = item_name
        self.area = area

    def __str__(self):
        """
        这里返回的必须是
        :return:
        """
        return f'{self.item_name}占地{self.area}平方米'


class House:
    def __init__(self, house_type, area):
        self.house_type = house_type
        self.area = area
        self.free_area = area  # 剩余空间
        self.item_list = []  # 家具列表

    def __str__(self):
        return f'房子中现在有这些家具：{self.item_list}\n剩余面积{self.free_area}'

    def add_item(self, item: HouseItem):  # :后的是注解，方便写代码
        if self.free_area > item.area:
            print(f"添加家具：{item.item_name}")
            self.item_list.append(item.item_name)
            self.free_area = self.free_area - item.area
        else:
            print(f"房间空间不足")


if __name__ == '__main__':
    # cqz = Person('cqz', 18, 90)
    # cqz.run()
    # cqz.eat()
    # print(cqz)
    bed = HouseItem("席梦思", 4)
    chest = HouseItem("衣柜", 2)
    table = HouseItem("餐桌", 1.5)
    my_house = House('三室一厅', 70)
    print(my_house)
    my_house.add_item(bed)
    print(my_house)
    my_house.add_item(table)
    print(my_house)
